package com.admin.util;

import com.fasterxml.jackson.annotation.JsonValue;

import java.io.Serializable;

public class Result<T> implements Serializable {


    private static final long serialVersionUID = 6230939589190169253L;

    /**
     * 响应状态码
     */
    public enum Code{
        SUCCESS(0, "成功"),
        SYSTEMERROR(1001, "系统出了点小bug，请联系开发人员"),
        REQUESTERROR(1002, "请求错误"),
        FAILED(1003, "失败"),
        SIGNERROR(1004, "签名错误"),
        PARAMERROR(1005, "参数错误"),
        ROLEBAN(1006,"权限不足"),
        UNIQUECONSTRAINTERROR(1007, "数据唯一属性冲突"),
        AUTHERROR(1008, "数据唯一属性冲突"),
        NEEDLOGIN(1009,"需要登录");
        private int code;
        private String errorMessage;



        private Code(int code, String errorMessage) {
            this.code = code;
            this.errorMessage = errorMessage;
        }

        @JsonValue
        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }
    }

    /**
     * 响应状态码:
     * 可用值:0:成功
     * 1001:系统错误
     * 1002:请求错误
     * 1003:失败
     * 1004:签名错误
     * 1005:参数错误
     * 1006:权限不足
     * 1007:数据唯一属性冲突
     * 1008:数据属性冲突
     * 1009:需要登录
     */
    private Code code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private Object data;
    /**
     * 响应数据条数
     */
    private long count;
    public void setMessage(String message) {
        this.message = message;
    }
    public long getCount() {
        return count;
    }



    public void setCount(long count) {
        this.count = count;
    }
    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public Code getCode() {
        return code;
    }

    public void setCode(Code code) {
        this.code = code;
        this.message=code.getErrorMessage();
    }

    public Result() {

    }

    public Result(Code code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Code code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public void setMessage(Code code, String message) {
        this.code = code;
        this.message = message;
    }

    public void setMessage(Code code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
